<template>
  <div style="font-size: 14px;background-color: #f5f5f5;height: 100%;">
    <div>
      <div class="order-box">
        <div class="order-item" v-for="(item1,index1) in orders" :key="index1">
          <div class="item-top">
            <div class="left">
              <img src="../../assets/img//logo.png">
              <span>香奈儿</span>
            </div>
            <div class="right">
              已付款
            </div>
          </div>
          <div class="item-li" v-for="(item2,index2) in item1.products" :key="index2+'_2'">
            <div class="img">
              <img :src="require('../../assets/img//'+item2.img)">
            </div>
            <div class="product-name">
              {{item2.productName}}
            </div>
            <div class="right">
              <div class="price">
                ¥{{item2.price}}
              </div>
              <div class="num">
                x{{item2.num}}
              </div>
            </div>
          </div>
          <div class="time-box">
            <div class="time">
              {{item1.createTime}}
            </div>
            <div class="right">
              <span class="num">共{{item1.totalNum}}件商品</span>
              <span class="price-text">应付金额：</span>
              <span class="price">{{item1.totalPrice}}元</span>
            </div>
          </div>
          <div class="but-box">
<!--            <van-button type="default" size="small">取消订单</van-button>-->
<!--            <van-button type="danger" size="small" plain >立即付款</van-button>-->
          </div>
        </div>
      </div>

      <van-empty v-if="orders.length === 0" description="暂无商品" />

    </div>
  </div>
</template>

<script>
  import { getStore,setStore } from "@/store/store.js";
  import { Empty } from 'vant';
  export default {

    components: {
      [Empty.name]: Empty,
    },

    data() {
      return {
        tabIndex: 1,
        orders: [],
      };
    },
    mounted() {
      this.$store.commit('SET_HEADER_FOOTER', {showSearchHeader: true,headerName:'商品订单',pageName:'order',showFooter: false});
      this.getOrders();
    },
    methods: {
      //订单列表
      getOrders(){
        let orderList = getStore({name:'order_list'});
        if(orderList){
          orderList.forEach(item1=>{
            let totalNum = 0;
            let totalPrice = 0;
            item1.products.forEach(item2=>{
              totalNum += parseInt(item2.num);
              totalPrice += parseFloat(item2.price) * parseInt(item2.num);
            })
            item1['totalNum'] = totalNum;
            item1['totalPrice'] = totalPrice;
          })
          this.orders = orderList;
        }
      }
    }
  };
</script>

<style scoped>
  .order-item{
    margin-top: 20px;
    background-color: #FFFFFF;
  }
  .order-item .item-top{
    height: 30px;
    line-height: 30px;
    display: flex;
    padding: 0 20px;
    border-bottom: 1px solid #eee;
  }
  .order-item .item-top .left{
    display: flex;
  }
  .order-item .item-top .left img{
    width: 20px;
    height: 20px;
    margin-top: 5px;
    margin-right: 10px;
  }
  .order-item .item-top .right{
    flex: 1;
    color: #ff6700;
    text-align: right;
  }
  .item-li{
    height: 80px;
    display: flex;
    padding: 0 20px;
  }
  .item-li .img{
    width: 50px;
  }
  .item-li .img img{
    width: 50px;
    height: 50px;
    margin-top: 15px;
  }
  .item-li .product-name{
    flex: 1;
    line-height: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    line-clamp: 1;
    -webkit-box-orient: vertical;
    margin-left: 10px;
  }
  .item-li .right{
    width: 60px;
    color: rgba(0,0,0,.5);
    text-align: right;
  }
  .item-li .right div{
    height: 40px;
    line-height: 40px;
  }

  .time-box{
    height: 40px;
    line-height: 40px;
    display: flex;
    padding: 0 20px;
    border-top: 1px solid #eee;
  }
  .time-box .time{
    color: #919191;
    font-size: 12px;
  }
  .time-box .right{
    flex: 1;
    text-align: right;
  }
  .time-box .right .num{
    margin-right: 5px;
  }
  .time-box .right .price{
    color: rgba(0,0,0,.5);
  }
  .but-box{
    text-align: right;
    padding: 10px 20px;
  }
  .cancel-but{
    height: 50px;
    line-height: 50px;
    padding: 5px 10px;
    color: #999;
    border: 1px solid #999;
  }
  .pay-but{
    height: 50px;
    line-height: 50px;
    padding: 5px 10px;
    color: #ff6700;
    border: 1px solid #ff6700;
    margin-left: 10px;
  }
</style>
